<template>
  <el-dialog v-model="show" width="1124px" :before-close="closeDialog">
    <div class="ecology-detail">
      <div class="ecology-detail-top f f-jb">
        <div class="ecology-detail-img">
          <el-carousel height="263px">
            <el-carousel-item v-for="(i, k) in info.image" :key="k">
              <div class="f f-jc f-ac" style="height: 100%">
                <img
                  :src="publicSrc(i)"
                  draggable="false"
                  style="max-width: 173px; max-height: 260px; margin: auto"
                />
              </div>
            </el-carousel-item>
          </el-carousel>
        </div>
        <div class="ecology-detail-info">
          <Title
            :title="info.name"
            color="#000"
            size="36"
            bold="700"
            left="0"
            :line-height="60"
          />
          <div class="ecology-detail-content">
            <div class="line-8">
              {{ info.synopsis }}
            </div>
            <div class="ecology-btn" @click="handleSeek">立即咨询</div>
          </div>
        </div>
      </div>
      <div class="ecology-detail-bottom">
        <Title title="产品参数" color="#000" size="14" bold="700" left="0" class="mt20" />
        <div class="ecology-detail-content">{{ info.parameter }}</div>
        <Title title="产品介绍" color="#000" size="14" bold="700" left="0" class="mt20" />
        <div v-html="info.introduce" class="ecology-detail-content" />
      </div>
    </div>
  </el-dialog>
</template>
<script setup lang="ts">
import { publicSrc } from "@/utils/common";
import { productDetail } from "@/api/ecology";

const props = defineProps({
  // 显示弹窗
  modelValue: {
    type: Boolean,
    default: false,
  },
  // 产品ID
  id: {
    type: [Number, String],
    default: "",
  },
});
const emit = defineEmits(["update:modelValue", "close", "comfirm"]);

const info = ref<any>({}); // 产品详情

const show = computed({
  get() {
    return props.modelValue;
  },
  set(val) {
    emit("update:modelValue", val);
  },
});

watch(
  () => props.modelValue,
  (val) => {
    if (val) {
      getInfo();
    }
  }
);

// 获取详情
const getInfo = () => {
  productDetail(props.id).then((res: any) => {
    if (res.code === 200) {
      let data = res.data;
      data.image = data.image ? data.image.split(",") : [];
      info.value = data;
    }
  });
};

// 关闭弹窗
const closeDialog = () => {
  show.value = false;
  emit("close", false);
};

// 咨询
const handleSeek = () => {
  emit("comfirm", info.value);
  closeDialog();
};
</script>
<style lang="scss" scoped>
.ecology-detail {
  height: 750px;
  padding: 0 20px;
  overflow-y: auto;
  &-top {
    height: 318px;
    border-bottom: 1px solid #e5e5e5;
    .ecology-detail-img {
      height: 293px;
      width: 260px;
      border: 1px solid #e5e5e5;
    }
    .ecology-detail-info {
      width: 738px;
      position: relative;
    }
  }
  &-bottom {
    width: 100%;
  }
  &-content {
    font-size: 14px;
    line-height: 19.6px;
    color: #383838;
    .ecology-btn {
      position: absolute;
      bottom: 25px;
      width: 126px;
      height: 47px;
      color: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
      background-color: #4580dd;
      &:hover {
        cursor: pointer;
        background-color: #4174c5;
      }
    }
  }
}
</style>
